<?php
class UserAgentsController extends AppController {

    public $name = 'UserAgents';

    public function beforeFilter(){
        parent::beforeFilter();
        $this->Auth->allow('*');
    }

    public function index() {
        $this->UserAgent->recursive = 0;
        $this->set('userAgents', $this->paginate());
    }

    public function view($id = null) {
        if (!$id) {
            $this->Session->setFlash(__('Invalid UserAgent.', true));
            $this->redirect(array('action'=>'index'));
        }
        $this->set('userAgent', $this->UserAgent->read(null, $id));
    }

    public function add() {
        if (!empty($this->data)) {
            $this->UserAgent->create();
            if ($this->UserAgent->save($this->data)) {
                $this->Session->setFlash(__('The UserAgent has been saved', true));
                $this->redirect(array('action'=>'index'));
            } else {
                $this->Session->setFlash(__('The UserAgent could not be saved. Please, try again.', true));
            }
        }
    }

    public function edit($id = null) {
        if (!$id && empty($this->data)) {
            $this->Session->setFlash(__('Invalid UserAgent', true));
            $this->redirect(array('action'=>'index'));
        }
        if (!empty($this->data)) {
            if ($this->UserAgent->save($this->data)) {
                $this->Session->setFlash(__('The UserAgent has been saved', true));
                $this->redirect(array('action'=>'index'));
            } else {
                $this->Session->setFlash(__('The UserAgent could not be saved. Please, try again.', true));
            }
        }
        if (empty($this->data)) {
            $this->data = $this->UserAgent->read(null, $id);
        }
    }

    public function delete($id = null) {
        if (!$id) {
            $this->Session->setFlash(__('Invalid id for UserAgent', true));
            $this->redirect(array('action'=>'index'));
        }
        if ($this->UserAgent->del($id)) {
            $this->Session->setFlash(__('UserAgent deleted', true));
            $this->redirect(array('action'=>'index'));
        }
    }

}
?>